//
//  DishRelateView.m
//  XRmenu
//
//  Created by gaomz on 11-3-28.
//  Copyright 2011 E0571. All rights reserved.
//

#import "DishRelateView.h"
#import "DishRelateDetailView.h"

@implementation DishRelateView

-(id)initWithViewName:(NSString *)vname
{
	NSDictionary* aDic = [self findNode:APPSESSION.allconfig withKey:vname];
	if ((self=[super initWithConfig:aDic])) {
		[self add1fingerLeftSwipe];
		[self add1fingerRightSwipe];
	}
	return self;
}



-(void)showRelateDish:(NSArray *)arrProducts
{
	UIView *scrView = [self viewWithTag:321];
	if (scrView) {
		[scrView removeFromSuperview];
	}
	NSInteger dishNum = [arrProducts count];
	if (dishNum>0) {
		UIImageView *view1=(UIImageView *)[self viewWithTag:kTagOfStartImgV+1];
		UIImageView *view2=(UIImageView *)[self viewWithTag:kTagOfStartImgV+2];
		UIImageView *view3=(UIImageView *)[self viewWithTag:kTagOfStartImgV];
		
		[view1 setHidden:YES];
		[view2 setHidden:YES];	
		[view3 setHidden:YES];
		switch (dishNum) {
			case 1:
				[view1 setHidden:NO];
				break;
			case 2:
				[view2 setHidden:NO];
				break;
			default:
				[view3 setHidden:NO];
				break;
		}
		
		
	
		arrRelateDish = [arrProducts copy];
		UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width,self.frame.size.height)];
	
		scrollView.directionalLockEnabled = YES;
		//scrollView.pagingEnabled = YES;
		//scrollView.backgroundColor = [UIColor blueColor];
		scrollView.showsVerticalScrollIndicator = NO;
		scrollView.showsHorizontalScrollIndicator = YES;

		UIView *detailView =[[DishRelateDetailView alloc] initWithViewName:@"Dish Relate Detail View" product:[arrRelateDish objectAtIndex:0]];

		CGSize newSize = CGSizeMake(detailView.frame.size.width * [arrRelateDish count],  self.frame.size.height);
		[scrollView setContentSize:newSize];
		[scrollView setTag:321];
		[self addSubview:scrollView];
	
		
		
		[scrollView addSubview:detailView];
		[detailView release];
	
		for (int i=1; i<[arrRelateDish count]; i++) {
			detailView =[[DishRelateDetailView alloc] initWithViewName:@"Dish Relate Detail View" product:[arrRelateDish objectAtIndex:i]];
			detailView.frame=CGRectMake(i*detailView.frame.size.width, detailView.frame.origin.y, detailView.frame.size.width, detailView.frame.size.height);
			[scrollView addSubview:detailView];
			[detailView release];
		}

		[arrRelateDish release];
	}
	
}



#pragma mark 手势操作
- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
	

}

- (void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer {
	

	
}



#pragma mark 语言切换
-(void) changeLanguage:(NSNotification *)notification
{
	// todo: 切换语言
	NSDictionary *dict = [APPSESSION.allconfig findAtPath:[NSString stringWithFormat:@"UI Skin/%@/Dish Main View/Dish Photo View/Dish Detail View", APPSESSION.uistyle]];
	if (dict) {
		NSArray *bts = (NSArray*)[dict objectForKey:@"button list"];
		[self translateButtons:bts];
	}
	
}

-(void)dealloc
{
	
	[super dealloc];
}

@end
